package com.example.comitclx1.service.impl;

import com.example.comitclx1.mapper.EmpMapper;
import com.example.comitclx1.pojo.Emp;
import com.example.comitclx1.pojo.PageBean;
import com.example.comitclx1.service.EmpService;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
@Service
public class EmpServiceImpl implements EmpService {

    @Autowired
    private EmpMapper empMapper;
    @Override
    public PageBean page(Integer page, Integer pageSize, String name, Short gender, LocalDate begin, LocalDate end) {
        PageHelper.startPage(page,pageSize);
        //2.执行查询
        List<Emp> empList=empMapper.list(name,gender,begin,end);
        Page<Emp> p = (Page<Emp>) empList;
        //3.封装
        return new PageBean(p.getTotal(),p.getResult());
    }



    @Override
    public void delete(List<Integer> ids) {
        empMapper.delete(ids);
    }

    @Override
    public void inset(Emp emp) {
        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.inset(emp);
    }

    @Override
    public Emp getById(Integer id) {
      Emp emp=empMapper.getById(id);
      return emp;
    }

    @Override
    public void update(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.update(emp);
    }

    @Override
    public Emp login(Emp emp) {
      return empMapper.getByUsernameAndPassword(emp);
    }

    @Override
    public void getByDeptId(Integer id) {
        empMapper.getByDeptId(id);
    }
}
/* public PageBean page(Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
                log.info("1");
              //2.执行查询
              List<Emp> empList=empMapper.list();
              log.info("2");
              Page<Emp>p = (Page<Emp>) empList;
              //3.封装
              return new PageBean(p.getTotal(),p.getResult());
          }*/
/* //获取所有条数据
       long sum= empMapper.count();
        //获取多少页数数据
        Integer begin=(page-1)*pageSize;
        List<Emp> page1= empMapper.pagesum(begin,pageSize);
        //返回对象
        return new PageBean(sum,page1);*/